package cn.com.bluemoon.daps.model.core.file.export;

import cn.com.bluemoon.daps.common.exception.DapThrowException;
import cn.com.bluemoon.daps.domp.api.FastDFSService;
import cn.com.bluemoon.daps.model.core.file.export.impl.FastDfsFileExport;
import cn.com.bluemoon.daps.model.core.file.export.impl.WorkbookFileExport;
import cn.com.bluemoon.daps.model.core.file.parser.FileType;

/**
 * 导出策略定义
 *
 * @author Jarod.Kong
 * @date 2021/3/23 10:16
 */
public enum ExportStrategy {
    /**
     *
     */
    Excel_OutputStream(new FileType[]{FileType.EXCEL}) {
        @Override
        public IFileExport<?> getFileExportClz(Object globalConfig) {
            return new WorkbookFileExport();
        }
    },
    /**
     * fastdfs
     */
    FastDFS(FileType.values()) {
        @Override
        public IFileExport<?> getFileExportClz(Object globalConfig) {
            if (globalConfig != null) {
                try {
                    FastDFSService fastDFSService = (FastDFSService) globalConfig;
                    return new FastDfsFileExport(fastDFSService);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new DapThrowException("使用FastDfs必须指定FastDFSService实例作为入参");
                }
            }
            return null;
        }
    };

    private final FileType[] fileType;

    ExportStrategy(FileType[] fileType) {
        this.fileType = fileType;
    }

    public FileType[] getFileType() {
        return fileType;
    }

    public IFileExport<?> getFileExportClz(Object globalConfig) {
        return null;
    }
}